$(function () {
  
    var questionId= getQueryString("questionId");
    console.log(questionId);
    //根据id从数据库中获取修改前的值
    $.post(
        "/citrusmonitor/question.do?method=findQById&questionId="+questionId,

        function (data) {
        	console.log(data)
         $("#question_id").val(data.questionId),
	     $("#user_id").val(data.userId),
	     $("#presenter").val(data.presenter),
         $("#summary").val(data.summary),
         $("#content").val(data.content),
         $("#file_path").val(data.filePath),
         $("#create_time").val(data.createTime),
	     $("#status").val(data.status)
        },
        "json"
    );
    //edit按钮绑定事件
    $("#edit").click(function () {
    	
    	 var formData = new FormData(); 
    	 formData.set("questionId",$("#question_id").val());
    		formData.set("userId",$("#user_id").val());
    		formData.set("presenter",$("#presenter").val());
    		formData.set("summary",$("#summary").val());
    		formData.set("content",$("#content").val());
    		formData.set("createTime",$("#create_time").val());
    		formData.set("status",$("#status").val());
    		formData.set("filePath", document.getElementById("file_path").files[0]);
//    		formData.set("imgPath",$("#img_path").val());
    	    $.ajax({
    	        url: "/citrusmonitor/question.do?method=modifyQ",
    	        type: "post",
    	        data:formData, 
    	        processData:false, 
    	        contentType:false, 
    	      
    	        dataType: "json",
    	        success: function (msg) {
    	        	console.log(msg)
    	            if (msg.status==1) {
    	                alert("修改信息成功");
    	                window.location.href="show.html";
    	            } else {
    	                alert("修改信息失败" );
    	            }
    	        },
    	        error:function(){
    	            alert("资源加载失败！！！");
    	        }
    	    })
/*
        $.post(
            "/citrusmonitor/question.do?method=modifyQ",
            {
            	"questionId": $("#question_id").val(),
                "userId": $("#user_id").val(),
                "presenter": $("#presenter").val(),
                "summary": $("#summary").val(),
                "content": $("#content").val(),
                "filePath": $("#file_path").val(),
                "createTime": $("#create_time").val(),
                "status": $("#status").val()
            },
           function(res){
                console.log(res);
                res = JSON.parse(res);
                if(res.status==1){
                    alert("信息提示修改成功");
                }else{
                    alert("信息提示修改失败");
                }}
        )*/
    })
})

function getQueryString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
 /*   console.log(reg );*/
    var r = window.parent.document.getElementById("rightframe").contentWindow.location.search.substr(1).match(reg);
    if(r!=null){
        return  unescape(r[2]);
    }
    return null;
}
